/*
 * @Author: Aro
 * @Date: 2021-10-14 09:33:59
 */

// https://leetcode-cn.com/problems/roman-to-integer/

/**
 * @param {string} s
 * @return {number}
 */
var romanToInt = function(s) {
  var romanObj = {
    'I': 1,
    'V': 5,
    'X': 10,
    'L': 50,
    'C': 100,
    'D': 500,
    'M': 1000
  };
  var answer = 0;
  const n = s.length;
  for (var i = 0; i < n; i++) {
    const value = romanObj[s[i]];
    if (i < n && value < romanObj[s[i + 1]]) {
      answer -= value;
    } else {
      answer += value;
    }
  }
  return answer;
};

console.log("====== start ======");

var test1 = romanToInt('VI');
console.log(test1);

console.log("====== end ======");